<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<jsp:useBean id="loginBean" class="mybean.data.login" scope="session"/>
<%@page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>我的订单</title>
	<link rel="stylesheet" type="text/css" href="css/reset.css">
	<link rel="stylesheet" type="text/css" href="css/common.css">
	<link rel="stylesheet" type="text/css" href="css/index-2.css">
	<link rel="stylesheet" type="text/css" href="css/index-1.css">
</head>
<body>	
	<%	request.setCharacterEncoding("utf-8");
		if(loginBean==null){
			out.println("<script language = javascript>alert('请重新登录!');");
			out.println("location.href='index.jsp'</script>");
			return;
		}
		else{
			boolean b=loginBean.getLogname()==null || loginBean.getLogname().length()==0;
			if(b){
				out.println("<script language = javascript>alert('请重新登录!');");
				out.println("location.href='index.jsp'</script>");
				return;
			}
		}
		String role=loginBean.getrole();
		if(role.equals("user")){%>
			<%@ include file="head.txt" %>
		<%}
		else{%>
			<%@ include file="Ahead.txt" %>
		<% }
		try {//加载驱动
			Class.forName("com.mysql.cj.jdbc.Driver");
	 	}
		catch(Exception e) {}
		String url = "jdbc:mysql://127.0.0.1:3306/bike?&useSSL=false&serverTimezone=GMT%2B8";
		Connection con = null;
		Statement sql = null;
		String id="",mess="",condition="";
		String name = request.getParameter("Nickname");//获取该订单信息的用户账户
		if(name==null){	name=loginBean.getLogname();}//普通用户登录时获取到的是null
		System.out.println(name);
		if(name.equals(loginBean.getLogname()))//登录用户自己查自己的订单
			condition = "select * from orderform where username='"+loginBean.getLogname()+"'";
		else
			condition = "select * from orderform where username='"+name+"'";//管理员查看有订单的用户的订单
		System.out.println(loginBean.getLogname());
		try {//连接数据库,获取用户订单
			con = DriverManager.getConnection(url,"root","744615");
			System.out.println("连接数据库成功");
			sql=con.createStatement();
			ResultSet rs=sql.executeQuery(condition);
			boolean m=rs.next();
			if(m==true){//订单中有记录，说明该用户有借车
				id = rs.getString("id");
				mess = rs.getString("mess");
					
	%><center class="Admin-content"><h3><%=name %>的订单</h3><br>
			<table>
				<tr style="background-color: #004b97;color: white"><th width=80 height=30>单车编号</th><th width=300 height=30>单车信息</th></tr>
				<tr style="background-color: #c0c0c0;"><td height=50><center><%=id %></center></td>
					<td height=50><center><%=mess %></center></td></tr><br>
			</table></center><br><br>			
	<%		System.out.println(id);
			System.out.println(mess);
				}
			else//订单中没有记录，说明该用户没有借车
				if(name.equals(loginBean.getLogname())){
					out.println("<script language = javascript>alert('没有订单，请先借车!');");
					out.println("location.href='borrow.jsp'</script>");
				}
			sql.close();
			con.close();
		}
		catch (SQLException exp){
			System.out.println(exp);
		}
	%>
</body>
</html>